package com.syg.servlet04._04_from;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 生成token
 */
@WebServlet("/prevent")
public class _01_FromServletController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String token = _03_TokenProccessor.getInstance().makeToken();//创建令牌
        System.out.println("在FromServletController中生成的token："+token);
        req.getSession().setAttribute("token", token);  //在服务器使用session保存token(令牌)
        req.getRequestDispatcher("/WEB-INF/JspPage/servlet04/_04_from/FromServletController.jsp").forward(req, resp);//跳转到form.jsp页面(转发)
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
